package com.usmarter.server.db;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import com.usmarter.model.IEntity;

public class CRUD<T extends IEntity> {
	private int id = 0;
	private Map<Long, T> db = new HashMap<Long, T>(); 

	public CRUD() {}

	public long create(T resource) {
		resource.setId(id++);
		db.put(resource.getId(), resource);
		return resource.getId();
	}

	public T get(long id) {
		return db.get(id);
	}
	
	public Collection<T> getAll() {
		return db.values();
	}

}
